﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using NHibernate.Cfg;
using Redboil.Bfp.Core;

namespace Redboil.Practices.Wcf {
    public partial class SampleView : System.Web.UI.Page {
        protected void Page_Load(object sender, EventArgs e) {

        }

        protected void ButtonCreateSchema_Click(object sender, EventArgs e) {
            //ISessionFactory sessionFactory = Container.Instance.Resolve<ISessionFactory>("nhibernate.factory.sqlite");

            //Castle.Facilities.NHibernateIntegration.Builders.DefaultConfigurationBuilder configBuilder = new Castle.Facilities.NHibernateIntegration.Builders.DefaultConfigurationBuilder();
            //Castle.Core.Configuration.IConfiguration castleConfig = Container.Instance.Kernel.ConfigurationStore.GetFacilityConfiguration("nhibernate").Children[0];
            //Configuration nhibernateConfig = configBuilder.GetConfiguration(castleConfig);

            Configuration nhibernateConfig = Container.Instance.Resolve<Configuration>();
            NHibernate.Tool.hbm2ddl.SchemaExport schemaExport = new NHibernate.Tool.hbm2ddl.SchemaExport(nhibernateConfig);
            schemaExport.SetOutputFile(Server.MapPath(Request.ApplicationPath + "/Redboil.Bfp.sql"));
            //schemaExport.Drop(true, true); // 生成表结构存在性判断并删除
            schemaExport.Create(true, true); // 生成脚本,先执行删除再执行创建操作
            Response.Write("<script>alert('生成脚本成功！');</script>");
            //return JavaScript("$('#divResultText').html('生成脚本成功！');");
        }
    }
}